package com.magicsoft.app.wcf;

import im.fir.sdk.http.JsonHttpResponseHandler;
import android.content.Context;

import com.google.gson.Gson;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

public class AsyncHttpServiceHelper {
	public Context context;

	public static AsyncHttpClient client = new AsyncHttpClient();

	public final Gson gson = new Gson();

	// public BaseService(Context context) {
	//
	// this.context = context;
	//
	// // client.addHeader("Content-Type",
	// // "application/x-www-form-urlencoded;charset=UTF-8");
	// // client.setTimeout(30000);
	//
	// }

	/**
	 * GET方式请求 不带参数
	 * 
	 * @param url
	 * @param responseHandler
	 */
	public static void get(String url, AsyncHttpResponseHandler responseHandler) {
		client.setTimeout(30 * 1000);
		client.get(url, responseHandler);
	}

	/**
	 * GET方式请求 带参数
	 * 
	 * @param url
	 * @param responseHandler
	 */
	public static void get(String url, RequestParams params,
			AsyncHttpResponseHandler responseHandler) {
		client.setTimeout(30 * 1000);
		client.get(url, params, responseHandler);

	}

	/**
	 * POST方式请求 不带参数
	 * 
	 * @param url
	 * @param params
	 * @param responseHandler
	 */
	public static void post(String url, AsyncHttpResponseHandler responseHandler) {
		client.setTimeout(30 * 1000);
		client.post(url, responseHandler);
	}

	/**
	 * POST方式请求 带参数
	 * 
	 * @param url
	 * @param params
	 * @param responseHandler
	 */
	public static void post(String url, RequestParams params,
			AsyncHttpResponseHandler responseHandler) {
		client.setTimeout(30 * 1000);
		client.post(url, params, responseHandler);
	}

	/**
	 * PUT方式请求 不带参数
	 * 
	 * @param url
	 * @param params
	 * @param responseHandler
	 */
	public static void put(String url, AsyncHttpResponseHandler responseHandler) {
		client.setTimeout(30 * 1000);
		client.put(url, responseHandler);
	}

	/**
	 * PUT方式请求 带参数
	 * 
	 * @param url
	 * @param params
	 * @param responseHandler
	 */
	public static void put(String url, RequestParams params,
			AsyncHttpResponseHandler responseHandler) {
		client.setTimeout(30 * 1000);
		client.put(url, params, responseHandler);
	}

	/**
	 * DELETE方式请求 带参数
	 * 
	 * @param url
	 * @param responseHandler
	 */
	public static void delete(String url,
			AsyncHttpResponseHandler responseHandler) {
		client.setTimeout(30 * 1000);
		client.delete(url, responseHandler);
	}


	// private static String getAbsoluteUrl(String relativeUrl) {
	// return BASE_URL + relativeUrl;
	// }
}
